import 'package:flutter/material.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/widgets.dart';

class SwitchDemo extends StatefulWidget {
  const SwitchDemo({Key? key}) : super(key: key);

  @override
  State<SwitchDemo> createState() => _SwitchDemoState();
}

class _SwitchDemoState extends State<SwitchDemo> {
  bool selectA = false;
  bool selectB = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:const Text("switch 基本使用") ,
        centerTitle: true,
      ),
      body: Column(
        children: [
         // 开关
         Container(
           width: 100,
           child: Switch(
             // 开关开启时的颜色
             activeColor: Colors.red,
             // 开关底座的颜色
             activeTrackColor: Colors.yellow,
             // 开关关闭状态时 圆点的颜色
             inactiveTrackColor: Colors.deepPurple,
             // 开关关闭状态时底座的颜色
             inactiveThumbColor: Colors.green,
             // 开关关闭状态时 圆点的背景
             inactiveThumbImage: AssetImage("assets/unselect.png"),
             // 开关开启状态时 背景图片
             activeThumbImage: AssetImage("assets/select.png"),
             // 当前开关的状态
             value: selectA, 
             onChanged: (value){
               setState(() {
                 selectA = value;
               });
             }),
         ),
         SizedBox(height: 20,),
         SwitchListTile(
           value: selectB, 
           onChanged: (value){
             setState(() {
               selectB = value;
             });
           },
           title: Text("这是一级标题"),
           subtitle: Text("这是二级标题"),
           secondary: Icon(Icons.home),
           )

         
        ],
      ),
    );
    
  }
}